import React from 'react';

export default class ErrorBoundary extends React.Component {
  constructor(props) {
    super(props);
    this.state = { hasError: false };
  }

  static getDerivedStateFromError(error) {
    console.log(error);
    // 忽略 ResizeObserver 错误
    if (error.message && error.message.includes('ResizeObserver')) {
      return { hasError: false };
    }
    return { hasError: true };
  }

  componentDidCatch(error, errorInfo) {
    console.log(error);
    // 忽略 ResizeObserver 错误
    debugger
    if (error.message && error.message.includes('ResizeObserver')) {
      return;
    }
    console.error('Error caught by boundary:', error, errorInfo);
  }

  render() {
    return this.props.children;
  }
}